<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="面料类型" class="myform-item">
          <el-input
            v-model="form.title"
            placeholder="请输入面料类型名称"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
          <el-button icon="el-icon-plus" type="" @click="onEdit()"
            >新增面料类型</el-button
          >
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column label="面料类型名称" align="center" prop="title">
      </el-table-column>
      <!-- <el-table-column label="状态" align="center" prop="status">
      </el-table-column> -->
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" size="default" @click="onEdit(row)"
            >编辑</el-button
          >
          <!-- <el-button
              type="text"
              style="color: red"
              size="default"
              @click="onDelete(row.id)"
              >禁用</el-button
            > -->
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminProductionGettypeslist"
    />
    <el-dialog
      title="编辑"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <div>
        <el-form ref="formdata" :model="formdata" class="myform">
          <el-form-item label="面料类型" class="myform-item">
            <el-input
              v-model="formdata.title"
              placeholder="请输入面料类型名称"
              clearable
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="onSubmit" :disabled="!formdata.title"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  postAdminProductionGettypeslist,
  postAdminCodeDelFabricMaintain,
  postApieditcategory,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      form: {
        title: "",
        page: 1,
        size: 10,
      },
      formdata: {
        fid: 0,
        title: "",
        types: 2,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postAdminProductionGettypeslist(form);
  },
  methods: {
    // 新增
    onAdd() {
      this.$router.push({ name: "LiningAdminDetail" });
    },
    // 删除
    onDelete(id) {
      let obj = {
        id,
      };
      this.$confirm("确定删除该面料?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminCodeDelFabricMaintain(obj).then((res) => {
            let form = this.form;
            this.postAdminProductionGettypeslist(form);
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    async onSubmit() {
      let { formdata, form } = this;
      await postApieditcategory(formdata);
      this.postAdminProductionGettypeslist(form);
      this.dialogVisible = false;
    },
    // 编辑
    onEdit(row) {
      if (row) {
        this.formdata.title = row.title;
        this.formdata.id = row.id;
      } else {
        this.formdata = {
          fid: 0,
          title: "",
          types: 2,
        };
      }
      this.dialogVisible = true;
    },
    // 采购列表
    async postAdminProductionGettypeslist(data) {
      this.loading = true;
      this.form = data;
      postAdminProductionGettypeslist(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminProductionGettypeslist(this.form);
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
  